home *** CD-ROM | disk | FTP | other *** search
- /*
- DUFTP
- */
-
- // GUI links to FTP
-
- #include <DULIB.H>
- #include <UNISTD.H>
- #include <FCNTL.H>
- #include "init.h"
- #include "globals.h"
- #include "servers.h"
- #include "ftp.h"
- #include "duftp_n.h"
-
- short open_selected_server(void)
- {
- OBJECT *oi;
- ICONBLK *ib;
- FILE *f;
- short n;
- char *d;
-
- set_dialog_text(Ftp_progress, Ftp_operation, "Opening FTP link.");
- set_dialog_text(Ftp_progress, Ftp_status, "Initialising.");
- activate_dialog(Ftp_progress, "DUftp Accessing Remote", DIAL_NO_CLOSE);
-
- // Chop all login/ip info's at first space, as you cann't have spaces in them anyway
- for(n=0; (selected_server->ip_name[n]!=' ')&&(selected_server->ip_name[n]!='\0'); n++);
- selected_server->ip_name[n]='\0';
- for(n=0; (selected_server->login[n]!=' ')&&(selected_server->password[n]!='\0'); n++);
- selected_server->login[n]='\0';
- for(n=0; (selected_server->password[n]!=' ')&&(selected_server->password[n]!='\0'); n++);
- selected_server->password[n]='\0';
-
- connect_to_server(selected_server->ip_name); // Actually connect to the server
-
- if (connected)
- login(selected_server->login, selected_server->password); // Login to the server
-
- sprintf(new_server_address,"%s",selected_server->ip_name);
- sprintf(new_server_login,"%s",selected_server->login);
- sprintf(new_server_password,"%s",selected_server->password);
- sprintf(new_server_path,"%s",selected_server->path);
-
- rsrc_gaddr(0,Mainwindow,&oi);
- ib=(ICONBLK*)(oi+Online_offline)->ob_spec;
-
- if (connected) // Update the gnatty on/offline icon.
- {
-
- // Change remote directory
- if (selected_server->path[0]!=' ')
- {
- set_dialog_text(Ftp_progress, Ftp_operation, "Setting initial directory.");
- set_dialog_text(Ftp_progress, Ftp_status, "Calling remote_cd.");
- remote_cd(selected_server->path);
- }
-
- d=remote_pwd();
- if (d) // If we can get the current remote directory, use it
- sprintf(new_server_path,"%s",d);
- else // Otherwise, just use the initial directory.
- sprintf(new_server_path,"/");
-
- set_dialog_text(Mainwindow, Remote_path, new_server_path);
-
- chdir(initial_dir);
- f=fopen("temp.fil","w");
- if(f) fclose(f);
-
- remote_ls("temp.fil",NULL);
-
- ib->ib_ptext="Online";
- (oi+Online_offline)->ob_state|=SELECTED;
- (oi+Open_server)->ob_state|=DISABLED;
- (oi+Open_new_server)->ob_state|=DISABLED;
- (oi+This_server)->ob_state&=~SHADOWED;
- (oi+This_server)->ob_state|=DISABLED;
- (oi+This_server)->ob_flags&=~SELECTABLE;
-
- if (remote_directory) dispose_file_list(remote_directory);
- remote_directory=ls_to_list("temp.fil");
- if (remote_files) free(remote_files);
- remote_files=extract_filenames(remote_directory);
- Change_scroll_list(Mainwindow, Remote_fs, remote_files, file_count+1);
- }else{
- ib->ib_ptext="Unconnected";
- (oi+Online_offline)->ob_state&=~SELECTED;
- (oi+Open_server)->ob_state&=~DISABLED;
- (oi+Open_new_server)->ob_state&=~DISABLED;
- (oi+This_server)->ob_state|=SHADOWED;
- (oi+This_server)->ob_state&=~DISABLED;
- (oi+This_server)->ob_flags|=SELECTABLE;
- }
-
- close_dialog(Ftp_progress);
- dialog_update(Mainwindow);
-
- return TRUE;
- }
-
- short open_new_server(void)
- {
- OBJECT *oi;
- ICONBLK *ib;
- FILE *f;
- short n;
- char *d;
-
- set_dialog_text(Ftp_progress, Ftp_operation, "Opening new FTP link.");
- set_dialog_text(Ftp_progress, Ftp_status, "Initialising.");
- activate_dialog(Ftp_progress, "DUftp Accessing Remote", DIAL_NO_CLOSE);
-
- for(n=0; new_server_address[n]!=' '; n++);
- new_server_address[n]='\0';
- for(n=0; new_server_login[n]!=' '; n++);
- new_server_login[n]='\0';
- for(n=0; new_server_password[n]!=' '; n++);
- new_server_password[n]='\0';
- for(n=0; new_server_path[n]!=' '; n++);
- new_server_path[n]='\0';
-
- connect_to_server(new_server_address); // Actually connect to the server
-
- if (connected)
- login(new_server_login, new_server_password); // Login to the server
-
- rsrc_gaddr(0,Mainwindow,&oi);
- ib=(ICONBLK*)(oi+Online_offline)->ob_spec;
-
- if (connected) // Update the gnatty on/offline icon.
- {
-
- // Change remote directory
- if (new_server_path[0]!=' ')
- {
- set_dialog_text(Ftp_progress, Ftp_operation, "Setting initial directory.");
- set_dialog_text(Ftp_progress, Ftp_status, "Calling remote_cd.");
- remote_cd(new_server_path);
- }
-
- d=remote_pwd();
- if (d) // If we can get the current remote directory, use it
- sprintf(new_server_path,"%s",d);
- else // Otherwise, just use the initial directory.
- sprintf(new_server_path,"/");
-
- set_dialog_text(Mainwindow, Remote_path, new_server_path);
-
- chdir(initial_dir);
- f=fopen("temp.fil","w");
- if(f) fclose(f);
-
- remote_ls("temp.fil",NULL);
-
- ib->ib_ptext="Online";
- (oi+Online_offline)->ob_state|=SELECTED;
- (oi+Open_server)->ob_state|=DISABLED;
- (oi+Open_new_server)->ob_state|=DISABLED;
- (oi+This_server)->ob_state&=~SHADOWED;
- (oi+This_server)->ob_state|=DISABLED;
- (oi+This_server)->ob_flags&=~SELECTABLE;
-
- if (remote_directory) dispose_file_list(remote_directory);
- remote_directory=ls_to_list("temp.fil");
- if (remote_files) free(remote_files);
- remote_files=extract_filenames(remote_directory);
- Change_scroll_list(Mainwindow, Remote_fs, remote_files, file_count+1);
- }else{
- ib->ib_ptext="Unconnected";
- (oi+Online_offline)->ob_state&=~SELECTED;
- (oi+Open_server)->ob_state&=~DISABLED;
- (oi+Open_new_server)->ob_state&=~DISABLED;
- (oi+This_server)->ob_state|=SHADOWED;
- (oi+This_server)->ob_state&=~DISABLED;
- (oi+This_server)->ob_flags|=SELECTABLE;
- }
-
- close_dialog(Ftp_progress);
- dialog_update(Mainwindow);
-
- return TRUE;
- }
-
- short close_current_session(void)
- {
- OBJECT *oi;
- ICONBLK *ib;
-
- disconnect();
-
- rsrc_gaddr(0,Mainwindow,&oi);
- ib=(ICONBLK*)(oi+Online_offline)->ob_spec;
-
- if (connected) // Update the gnatty on/offline icon.
- {
- ib->ib_ptext="Online";
- (oi+Online_offline)->ob_state|=SELECTED;
- (oi+Open_server)->ob_state|=DISABLED;
- (oi+Open_new_server)->ob_state|=DISABLED;
- (oi+This_server)->ob_state&=~SHADOWED;
- (oi+This_server)->ob_state|=DISABLED;
- (oi+This_server)->ob_flags&=~SELECTABLE;
- }else{
- ib->ib_ptext="Unconnected";
- (oi+Online_offline)->ob_state&=~SELECTED;
- (oi+Open_server)->ob_state&=~DISABLED;
- (oi+Open_new_server)->ob_state&=~DISABLED;
- (oi+This_server)->ob_state|=SHADOWED;
- (oi+This_server)->ob_state&=~DISABLED;
- (oi+This_server)->ob_flags|=SELECTABLE;
- }
-
- reset_remote_list();
-
- dialog_update(Mainwindow);
-
- return TRUE;
- }
-
- // Drag & Drop a filename from Remote_fs to Local_fs
- // If successful, FTP the file from the remote server.
- void get_file(char *filename)
- {
- FILE *f;
- OBJECT *TheDial;
- char alert[200];
- short ob,junk,mx,my,mb;
- short w,pt[8],tw,th;
-
- if (!connected) return;
-
- vqt_extent(x_handle, filename, pt);
- tw=pt[2]-pt[0];
- th=pt[1]-pt[7];
-
- graf_mkstate(&mx,&my,&mb,&junk);
- if (!mb) return;
-
- wind_update(BEG_MCTRL); // Drag & drop the filename
- graf_mouse(FLAT_HAND,NULL);
-
- graf_dragbox(tw,th,mx,my,scrn_x,scrn_y,scrn_w,scrn_h,&mx,&my);
-
- graf_mouse(ARROW,NULL);
- wind_update(END_MCTRL);
-
- w=wind_find(mx,my);
-
- if (w)
- {
- if (windows[w].the_dialog==Mainwindow)
- {
- rsrc_gaddr(0,Mainwindow,&TheDial);
- ob=objc_find(TheDial, 0, 5, mx, my); // Find the object we dropped filename on
-
- if (ob==Local_fs+scroll_text_area) // If it was Local_fs, then do an FTP get for it
- {
- sprintf(alert,"[1][ Get remote file : | '%s'. ][ Ok | Cancel ]",filename);
- if (form_alert(1,alert)==2) return;
-
- chdir(current_local_path); // Shift to the current directory
- f=fopen(filename,"w"); // Create the file
- if (f)
- {
- fclose(f);
- }else{
- form_alert(1,"[3][ Cann't create local file. ][ Cancel ]");
- return;
- }
-
- set_dialog_text(Ftp_progress, Ftp_operation, "Getting file from remote.");
- set_dialog_text(Ftp_progress, Ftp_status, "Initialising.");
- activate_dialog(Ftp_progress, "DUftp Accessing Remote", DIAL_NO_CLOSE);
-
- remote_get(filename,filename); // Fetch the file
-
- close_dialog(Ftp_progress);
-
- get_local_files(); // Update the local file list
- if (local_files) free(local_files);
- th=file_count;
- local_files=extract_filenames(local_directory);
- local_file_count=file_count;
- file_count=th;
- Change_scroll_list(Mainwindow, Local_fs, local_files, local_file_count+1);
- }
- }
- }
- }
-
- // Change the current remote directory, and get a new file list.
- void change_remote_directory(char *dir_name)
- {
- FILE *f;
- char *d;
-
- if (!connected) return;
-
- // Open remote progress window
- set_dialog_text(Ftp_progress, Ftp_operation, "Changing remote directory.");
- set_dialog_text(Ftp_progress, Ftp_status, "Calling remote_cd.");
- activate_dialog(Ftp_progress, "DUftp Accessing Remote", DIAL_NO_CLOSE);
-
- // Change remote directory
- remote_cd(dir_name);
-
- // Check where we ended up
- d=remote_pwd();
- if (d) // If we can get the current remote directory, use it
- sprintf(new_server_path,"%s",d);
- else // Otherwise, just use the initial directory.
- sprintf(new_server_path,"/");
-
- set_dialog_text(Mainwindow, Remote_path, new_server_path);
-
- // Request a new file list
- chdir(initial_dir);
- f=fopen("temp.fil","w");
- if(f) fclose(f);
- remote_ls("temp.fil",NULL);
- if (remote_directory) dispose_file_list(remote_directory);
- remote_directory=ls_to_list("temp.fil");
- if (remote_files) free(remote_files);
- remote_files=extract_filenames(remote_directory);
- Change_scroll_list(Mainwindow, Remote_fs, remote_files, file_count+1);
-
- // Close remote progress & update main window
- close_dialog(Ftp_progress);
- dialog_update(Mainwindow);
- }
-